package com.taofuxn.yycreazy.mvp.presenter;

import com.taofuxn.yycreazy.mvp.BasePresenter;
import com.taofuxn.yycreazy.mvp.model.NewsertJokBean;
import com.taofuxn.yycreazy.mvp.view.IGifView;
import com.taofuxn.yycreazy.retrofit.ApiStore;
import com.taofuxn.yycreazy.retrofit.Key;
import com.taofuxn.yycreazy.rxjava.ApiCallback;
import com.taofuxn.yycreazy.rxjava.SubscriberCallback;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by wanghuafu on 16/9/16.
 */
public class HappyGifPresenter extends BasePresenter {
    private IGifView mIGifView;

    public HappyGifPresenter(IGifView mIGifView) {
        onAttachView(mIGifView);
        this.mIGifView = mIGifView;
    }

    public void loadImgData(final boolean isReflash, int curpage) {

        HashMap<String, String> params = new HashMap<>();
        params.put("page", "" + curpage);
        params.put("pagesize", "20");
        params.put("key", Key.jokey);
        addSubscription(mRetrofit.create(ApiStore.class).getPhotoDataByNewest(params), new SubscriberCallback(new ApiCallback() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onFailed(int code, String msg) {

            }

            /**
             * @param o
             */
            @Override
            public void onSuccess(Object o) {
                NewsertJokBean response = (NewsertJokBean) o;
                mIGifView.dismissLoading();
                if (isReflash)
                    mIGifView.requestSuccess(response.result.data);
                else
                    mIGifView.loadMoreSuccess(response.result.data);
            }
        }));

    }


}
